using System;

namespace Touchmax
{
	public class OpInvoice
	{
		private int sequenceId;
		private string docType;
		private string docNo;
		private DateTime docDate;
		private string jobOrder;
		private string branchId;
		private string custId;
		private string term;
		private string remark;
		private decimal totAmt;
		private string userId;
		private DateTime entryDate;

		public int SequenceId
		{
			get { return this.sequenceId; }
		}

		public string DocType
		{
			get { return this.docType; }
			set { this.docType = value; }
		}

		public string DocNo
		{
			get { return this.docNo; }
			set { this.docNo = value; }
		}

		public DateTime DocDate
		{
			get { return this.docDate; }
			set { this.docDate = value; }
		}

		public string JobOrder
		{
			get { return this.jobOrder; }
			set { this.jobOrder = value; }
		}

		public string BranchId
		{
			get { return this.branchId; }
			set { this.branchId = value; }
		}

		public string CustId
		{
			get { return this.custId; }
			set { this.custId = value; }
		}

        public string CustName
        {
            get
            {
                string custName = "";
                if (this.custId != null)
                {
                    string sql = "select code from BoClient where custid='" + custId + "'";
                    custName = SafeValue.SafeString(Touchmax.Manager.ORManager.ExecuteScalar(sql), "");
                }
                return custName;
            }
        }


		public string Term
		{
			get { return this.term; }
			set { this.term = value; }
		}

		public string Remark
		{
			get { return this.remark; }
			set { this.remark = value; }
		}

		public decimal TotAmt
		{
			get { return this.totAmt; }
			set { this.totAmt = value; }
		}

		public string UserId
		{
			get { return this.userId; }
			set { this.userId = value; }
		}

		public DateTime EntryDate
		{
			get { return this.entryDate; }
			set { this.entryDate = value; }
		}

        public decimal Amount
        {
            get
            {
                decimal amt = 0;
                if (this.sequenceId != null && this.sequenceId > 0)
                {
                    string sql = "select sum(totamt) from opInvoiceDet where ItemId='" + this.sequenceId + "'";
                    amt = SafeValue.SafeDecimal(Touchmax.Manager.ORManager.ExecuteScalar(sql), 0);
                }
                return amt;
            }
        }
	}
}
